import functions from "./functions.js";
import {
	getToken
} from "@/utils/auth.js";
const apiUrl = `${functions.getDomain()}/api/port/upload`;

export default function({count,extension}) {
	return new Promise((relove, reject) => {
		uni.chooseFile({
			count: count, //默认100
			extension:extension,
			success: function (res) {
				console.log('选择的文件 file类型',res);
				//上传到服务器后 添加到fileValue
				
				uni.showLoading({
					title: '上传中',
					mask: true
				});
				let files = res.tempFilePaths.map((item,index) => {
					return {
						name:'files',
						file:res.tempFiles[index],
						uri:item
					}
				})
				uni.uploadFile({
					url: apiUrl,
					files: files,
					name: 'files',
					success: (opt) => {
						let data = JSON.parse(opt.data);
						console.log("文件返回", data);
						uni.hideLoading();

						if (data.code == 200) {
							relove(data.data);
						} else {
							reject();
						}
					},
					fail: (err) => {
						uni.hideLoading();
						reject();
					}
				});

				
				// questionList.value[index].multipleCurrent = 
				
			}
		});


	})

}